const env = process.env.NODE_ENV_MODE;
const path = require('path');
const webpack = require('webpack');

const dllPath = './dll';
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
const WebpackBar = require('webpackbar');

const publicPath = process.env.VUE_APP_PUBLIC_PATH;
module.exports = {
  publicPath,
  devServer: {
    host: '0.0.0.0',
    port: 8094,
    compress: true,
    proxy: {
      '/new/api': {
        target: 'https://develop.jsh.com/',
        changeOrigin: true,
        // pathRewrite: {
        //   '^/api': ''
        // },
        secure: false,
      },
    },
  },
  configureWebpack: (config) => {
    // eslint-disable-next-line no-empty
    if (env === 'dev') {
      config.plugins.push(
        new WebpackBar({
          name: '开发环境',
          color: '#552DA7',
        }),
      );
    } else {
      config.plugins.push(
        new webpack.DllReferencePlugin({
          context: process.cwd(),
          manifest: require(`${dllPath}/vendor-manifest.json`),
        }),
      );
      // / 将打包出来文件动态引入index.html
      config.plugins.push(
        new AddAssetHtmlPlugin({
          // dll文件位置
          filepath: path.resolve(`${__dirname}`, `${dllPath}/*.js`),
          // dll 引用路径
          // 去掉path.join,防止babel报错bug
          publicPath: '/dll',
          // dll最终输出的目录
          outputPath: dllPath,
        }),
      );
    }
  },
};
